{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Specifications for Jupyter notebooks as python scripts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Markdown cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Markdown cells are escaped with a single quote. Two consecutive\n",
    "cells are separated with a blank line."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Code cells"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Python code and adjacent comments are mapped to cell codes."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# For instance, this is a code cell that starts with a\n",
    "# code comment, where we define a variable\n",
    "a = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A cell with another variable\n",
    "b = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# In this cell we define a function\n",
    "def f(x):\n",
    "    return x + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Now simple function calls\n",
    "c = f(b)\n",
    "a * b + c"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Line breaks in code cells are supported but then the cell need to have\n",
    "metadata and an end-of-cell marker. Metadata information in json format,\n",
    "escaped with '#+' or '# +'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def g(x):\n",
    "    return x + 2\n",
    "\n",
    "\n",
    "d = 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# One more cell\n",
    "a * b + g(c) + d"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Raw cells, and cells active in py or ipynb only"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Raw cells are commented code cells with metadata \"active\": \"\"."
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "This is a raw cell"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Actually, using the \"active\" key you can have cells active in Jupyter\n",
    "and inactive in python scripts"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {
    "active": "py"
   },
   "source": [
    "1 + 1  # done only in py script, inactive (raw) in ipynb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "active": "ipynb"
   },
   "outputs": [],
   "source": [
    "2 + 2 # active in ipynb only"
   ]
  }
 ],
 "metadata": {
  "jupytext": {
   "cell_metadata_filter": "active,-all",
   "main_language": "python",
   "notebook_metadata_filter": "-all"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}